package mz.mobileservices.uem;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import static mz.mobileservices.uem.Constants.DATABASE_NAME;
import static mz.mobileservices.uem.Constants.TABLE_MCEL;
import static mz.mobileservices.uem.Constants.TABLE_BIM;
import static mz.mobileservices.uem.Constants.DATABASE_VERSION;
import static mz.mobileservices.uem.Constants.FAVORITOS;
import static mz.mobileservices.uem.Constants.FAVORITOS2;
import static mz.mobileservices.uem.Constants.LISTA;
import static mz.mobileservices.uem.Constants.TOKNICE;

public class DataBaseHelper extends SQLiteOpenHelper
{	 
    ContentValues values = new ContentValues();
    private SQLiteDatabase db;
   
    public DataBaseHelper(Context context) 
    {
    	super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    
    @Override
    public void onCreate(SQLiteDatabase db)
    {	   
    	db.execSQL("CREATE TABLE IF NOT EXISTS "+ LISTA
    			+ " (_id integer primary key autoincrement, nome text not null, numero text not null);");
    	
		 /* Create a Table mcel in the Database. */
		db.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE_MCEL
		+ " (_id integer primary key autoincrement, nome_menu text not null, descricao text not null);");
		
		/* Create a Table bim in the Database. */
		db.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE_BIM
    			+ " (_id integer primary key autoincrement, nome_menu text not null, descricao text not null);");
		
		/* Create a Table favoritos-BIM in the Database. */
		db.execSQL("CREATE TABLE IF NOT EXISTS "+ FAVORITOS
    			+ " (_id integer primary key autoincrement, nome text not null, apelido text not null, conta1 text not null, conta2 text not null);");
		
		/* Create a Table favoritos-others in the Database. */
		db.execSQL("CREATE TABLE IF NOT EXISTS "+ FAVORITOS2
    			+ " (_id integer primary key autoincrement, nome text not null, apelido text not null, nib text not null, conta text not null);");
		
		/* Create a Table toknice in the Database. */
		db.execSQL("CREATE TABLE IF NOT EXISTS "+ TOKNICE
    			+ " (_id integer primary key autoincrement, nome text not null, code integer not null);");
    }
   
    @Override
    public void onOpen(SQLiteDatabase db) 
    {
    	super.onOpen(db);
    	Log.i("DB Open", "DB Open OK!");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
    	Log.w("DB Upgrade", "Upgrading database from version " + oldVersion
    			+ " to "+ newVersion + ", which will destroy all old data");
    	onCreate(db);
    }
    
    @Override
	public synchronized void close() 
    {	
    	if(db != null)
    		    db.close();
 
    	 super.close();
	}
}